package main.java.com.blog.controller;


import com.blog.entity.Info;
import com.blog.service.InfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created by Admin on 2017/6/5.
 */
@Controller
@RequestMapping("/info")
public class InfoController {

    @Autowired
    InfoService infoService;


    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public String insert(String infoName,
                         String infoSex,
                         String year,
                         String month,
                         String day,
                         String infoHome,
                         String infoCulture) {
        Boolean b = false;
        Info info = new Info();
        info.setInfoName(infoName);
        info.setInfoSex(infoSex);
        info.setInfoTime(year + "/" + month + "/" + day);
        info.setInfoHome(infoHome);
        info.setInfoCulture(infoCulture);

        List<Info> infoList = infoService.findAll();
        for (int i = 0; i < infoList.size(); i++) {
            if (infoList.get(i).getInfoName().equals(infoName)) {
                b = true;
            }
        }
        if (b.equals(true)) {
            infoService.updateInfo(info);
        } else {
            infoService.addInfo(info);
        }
        return "../resources/privateIndex";
    }


}
